import java.awt.*;
import javax.swing.*;
import java.util.ArrayList;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;


public class Grafica3 extends JFrame{
    
    public static JFrame f;
    public static JPanel leftPanel;
    public static JPanel centerPanel;
    public static JPanel rightPanel;
    
    
    //creazione JPanel**********************************************************************
    public void createGraphic(){
        JMenuItem exit;
        JMenuItem saveGame;
        JMenuItem loadGame;
        JMenuItem newGame;
        JMenu jMenu;
        
        f = new JFrame("La ruota della fortuna");
//		JComboBox menu = new JComboBox();
        
        f.setBounds(150,50, 950,650);//posizione dove apparira il JFrame e dimensione
        
        f.setBounds(150,50, 950,650);//posizione dove apparir� il JFrame e dimensione
        f.setLayout(new BorderLayout(3,3));
        f.setBackground(Color.blue);
        f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);//se non lo metto una volta chiusa la finestrella che si viene a creare continuerebbe a rimanere in esecuzione
        f.addWindowListener(new CloseWarning());
        f.setVisible(true);
        f.setResizable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        
        
        
        f.setJMenuBar(new GameMenu().getMenu());
        
        
        //aggiungo a nord la combobox, a est, ovest e center i jpanel
//		f.add(new JMenuBar().add(menu), BorderLayout.NORTH);
        f.add(createLeftPanel(), BorderLayout.WEST);
        f.add(createCenterPanel(), BorderLayout.CENTER);
        f.add(createRightPanel(createVowelButtons(), createConsonantButtons()), BorderLayout.EAST);
        f.pack();
        
    }
    //****************************************************************************************fine JPanel
    
    
    //creazione leftPanel**********************************************************************
    public JPanel createLeftPanel(){
        
        leftPanel = new JPanel();
        JPanel one = new JPanel();
        JPanel two = new JPanel();
        JPanel three = new JPanel();
        
        leftPanel.setLayout(new BorderLayout(3,3));//suddivido il pannello di sx per inserire i 3 JTextArea relative ai giocatori in north, center e south
        leftPanel.setBackground(Color.black);
        leftPanel.setPreferredSize(new Dimension(150,600));
        one.setBackground(Color.red);
        one.setPreferredSize(new Dimension(150,200));
        two.setBackground(Color.red);
        two.setPreferredSize(new Dimension(150,200));
        three.setBackground(Color.red);
        three.setPreferredSize(new Dimension(150,200));
        
        
        JTextArea player1 = new JTextArea("Info giocatore1",1,4);//campi con le info relativa ai giocatori nella posizione west del BorderLayout
        JTextArea player2 = new JTextArea("Info giocatore2",1,4);
        JTextArea player3 = new JTextArea("Info giocatore3",1,4);
        player1.setBackground(Color.red);
        player2.setBackground(Color.red);
        player3.setBackground(Color.red);
        
        one.add(player1);
        two.add(player2);
        three.add(player3);
        
        leftPanel.add(new Player("pippo"), BorderLayout.NORTH);
        leftPanel.add(new Player("pluto"), BorderLayout.CENTER);
        leftPanel.add(new Player("paperino"), BorderLayout.SOUTH);
        
        return leftPanel;
    }
    //****************************************************************************************fine leftPanel
    
    
    //creazione centerPanel**********************************************************************
    public JPanel createCenterPanel(){
        
        centerPanel = new JPanel();
        JPanel four = new JPanel();//contiene il pulsante e il capo per darer la risposta
        JPanel five = new JPanel();//contiene il pannello con le lettere della manche
        JPanel six = new JPanel();//contiene la frase suggerimento
        JButton solution = new JButton("Invia la soluzione");//pulsante per inviare il testo in sendSolution
        JTextField sendSolution = new JTextField(30);//soluzione dell'utente
        
        centerPanel.setLayout(new BorderLayout(3,3));
        centerPanel.setBackground(Color.black);
        centerPanel.setPreferredSize(new Dimension(500,600));
        four.setPreferredSize(new Dimension(500,40));
        four.setBackground(Color.white);
        five.setPreferredSize(new Dimension(500,430));
        five.setBackground(Color.white);
        six.setPreferredSize(new Dimension(500,70));
        six.setBackground(Color.white);
        
        four.add(sendSolution);
        four.add(solution);
        
        centerPanel.add(four, BorderLayout.NORTH);
        centerPanel.add(five, BorderLayout.CENTER);
        centerPanel.add(six, BorderLayout.SOUTH);
        
        DrawCentralPanel dcp=new DrawCentralPanel();
        // dcp.drawHint(six,0);
        // dcp.drawPhrase(five);
        // dcp.drawSolution(four);
        
        
        return centerPanel;
    }
    //****************************************************************************************fine centerPanel
    
    
    //creazione rightPanel**********************************************************************
    public JPanel createRightPanel(ArrayList vow, ArrayList cons){
        
        rightPanel = new JPanel();
        JPanel seven = new JPanel();
        JPanel eight = new JPanel();
        JPanel nine = new JPanel();
        JButton throwWeel = new JButton("Gira la ruota!");
        JButton jolly = new JButton("Gioca il jolly");
        JTextArea value = new JTextArea("",1,1);
        JLabel vowel = new JLabel("Vocali");
        JLabel consonant = new JLabel("Consonanti");
        
        
        rightPanel.setLayout(new BorderLayout(3,3));
        rightPanel.setBackground(Color.black);
        rightPanel.setPreferredSize(new Dimension(250,600));
        seven.setPreferredSize(new Dimension(250,100));
        seven.setBackground(Color.red);
        eight.setPreferredSize(new Dimension(250,30));
        eight.setBackground(Color.red);
        nine.setPreferredSize(new Dimension(250,395));
        nine.setBackground(Color.red);
        //value.setBackground(Color.red); //questo andr� settato con il colore di sfondo del jframe seven
        
        
        //value.setBackground(Color.red); //questo andr� settato con il colore di sfondo del jframe seven
        
        
        
        seven.add(throwWeel);
        seven.add(value);
        seven.add(jolly);
        eight.add(vowel);
        nine.add(consonant);
        
        
        //riempe il pannello eight dei pulsanti relativi alle vocali
        for(int i=0; i<vow.size(); i++){
            
            eight.add((JButton)(vow.get(i)));
        }
        
        
        //riempe il pannello eight dei pulsanti relativi alle vocali
        for(int i=0; i<cons.size(); i++){
            
            nine.add((JButton)(cons.get(i)));
        }
        
        
        rightPanel.add(new WheelGui(), BorderLayout.NORTH);
        rightPanel.add(eight, BorderLayout.CENTER);
        rightPanel.add(nine, BorderLayout.SOUTH);
        
        
        return rightPanel;
    }
    //****************************************************************************************fine rightPanel
    
    
    //creo un arraylist di JButton rappresentanti le vocali
    public ArrayList createVowelButtons(){
        
        ArrayList<JButton> vow = new ArrayList<JButton>();
        
        JButton a = new JButton("A");
        JButton e = new JButton("E");
        JButton i = new JButton("I");
        JButton o = new JButton("O");
        JButton u = new JButton("U");
        
        vow.add(a);
        vow.add(e);
        vow.add(i);
        vow.add(o);
        vow.add(u);
        
        return vow;
    }
    
    
    
    //creo un ArrayList di Jbutton rappresentanti le consonanti
    public ArrayList createConsonantButtons(){
        
        ArrayList<JButton> cons = new ArrayList<JButton>();
        
        JButton b = new JButton("B");
        JButton c = new JButton("C");
        JButton d = new JButton("D");
        JButton f = new JButton("F");
        JButton g = new JButton("G");
        JButton h = new JButton("H");
        JButton j = new JButton("J");
        JButton k = new JButton("K");
        JButton l = new JButton("L");
        JButton m = new JButton("M");
        JButton n = new JButton("N");
        JButton p = new JButton("P");
        JButton q = new JButton("Q");
        JButton r = new JButton("R");
        JButton s = new JButton("S");
        JButton t = new JButton("T");
        JButton v = new JButton("V");
        JButton w = new JButton("W");
        JButton x = new JButton("X");
        JButton y = new JButton("Y");
        JButton z = new JButton("Z");
        
        
        cons.add(b);
        cons.add(c);
        cons.add(d);
        cons.add(f);
        cons.add(g);
        cons.add(h);
        cons.add(j);
        cons.add(k);
        cons.add(l);
        cons.add(m);
        cons.add(n);
        cons.add(p);
        cons.add(q);
        cons.add(r);
        cons.add(s);
        cons.add(t);
        cons.add(v);
        cons.add(w);
        cons.add(x);
        cons.add(y);
        cons.add(z);
        
        return cons;
        
    }
    
    public class CloseWarning extends WindowAdapter {
        
        public void windowClosing(WindowEvent e) {
            
            int ret = JOptionPane.showConfirmDialog(Grafica3.this, "Chiudere la finestra?",
                    "Grafica2", JOptionPane.YES_NO_OPTION);
            
            if (ret == JOptionPane.YES_OPTION){
                System.exit(0);
            }
        }
    }
    
    private void exitActionPerformed(java.awt.event.ActionEvent evt) {
        int ret = JOptionPane.showConfirmDialog(Grafica3.this, "Chiudere la finestra?",
                "Grafica2", JOptionPane.YES_NO_OPTION);
        
        if (ret == JOptionPane.YES_OPTION){
            System.exit(0);
        }
    }
    
    
    
    //metodo main
    public static void main(String[] v){
        
        Grafica3 gr = new Grafica3();
        gr.createGraphic();
    }
}
